﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufBase.h"
#include "GnufQtToolbar.h"
#include "GnufQtPushButton.h"
#include <QScrollArea>

namespace gnuf {
    class AppearanceSetting;
    class ScrollbarAppearanceSetting;

    class QtScrollArea final : public QScrollArea
    {
        Q_OBJECT

    public:
        // 临时接口
        static QString scrollBarStyleSheet(const AppearanceSetting *);
        static QString scrollBarStyleSheet(const ScrollbarAppearanceSetting &);

    public:
        explicit QtScrollArea(Item*, Direction dir = Direction::Horizontal, QWidget *parent = nullptr);
        virtual ~QtScrollArea() {
            disconnect(this); // no longer be a receiver
        }

        void refresh();
    public:
        void setContentWidget(QWidget*);
        QWidget* contentWidget() const;

        void useExcessButton(bool);
        inline bool hasExcessButton() const { return m_hasExcessBtn; }
        QPushButton* exBackwardButton() { return m_qtBackwardBtn; }
        QPushButton* exForwardButton()  { return m_qtForwardBtn; }

        void enableWheelAnimation(bool val) { m_enableWheelAnimation = val; }
        inline bool wheelAnimation() const { return m_enableWheelAnimation; }

        void setScrollStyleSheet(const std::wstring&);
        void preDestory();

        void scrollForward();
        void scrollBack();

    public slots:
        void onForwardBtnClick();
        void onBackBtnClick();
        void onRangeChanged(int, int);
        void onValueChanged(int);

    private:
        void scrollAnimation(int);
        void createExcessButton();
        void restore();

    private:
        Item* m_hostItem;
        Direction m_direction;
        gcmp::OwnerPtr<PushButton> m_exBackBtn;
        gcmp::OwnerPtr<PushButton> m_exForwardBtn;
        QtPushButton* m_qtBackwardBtn = nullptr;
        QtPushButton* m_qtForwardBtn  = nullptr;
        bool m_hasExcessBtn;
        bool m_enableWheelAnimation;
        static QString s_style;
    };
}
